import { Injectable } from "@nestjs/common";
import { InjectModel } from "@nestjs/mongoose";
import { Model } from "mongoose";
import { BookInfo } from "./book.interface";
import { BookDocument } from "./book.entity";

@Injectable()
export class BookService {
  constructor(@InjectModel('Book') private bookModel: Model<BookDocument>) {}
  private readonly books: BookInfo[] = [];

  async list() {
    const books = await this.bookModel.find().exec();
    return books;
  }

  async create(book: BookInfo) {
    this.books.push(book);
    const entity = await this.bookModel.create(book);
    return entity;
  }

  update() {
    return true;
  }

  detail() {
    return {}
  }

  remove() {
    return true;
  }
}